package br.here.data;

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import br.here.data.ILocalDAO;
import br.here.dominio.Local;
import br.here.exceptions.BDException;
import br.here.utils.HibernateUtil;

public class LocalDAOImpl extends GenericDAOImpl<Local>{

	public void addLocal(Local l) throws BDException {
		Session session = HibernateUtil.getCurrentSession();
		Transaction tx = session.beginTransaction();
		try{
			session.save(l);
			tx.commit();
		} catch (Throwable e){
			tx.rollback();
			throw new BDException();
		}
		
	}

	public Local findByName(String nome) throws BDException {
		// TODO Auto-generated method stub
		return null;
	}

	public Collection<Local> listAll() throws BDException {
		try {
			Session session =  HibernateUtil.getCurrentSession();
			Transaction tx = session.beginTransaction();
			Criteria c = session.createCriteria(Local.class);
			tx.commit();
			return c.list();
		} catch (Throwable e){
			throw new BDException();
		}
	}
	
	

}
